﻿#region Using directives

using System;
using System.Xml;
using System.Drawing.Design;
using System.ComponentModel;
using MCMLXVII.BackEnd.Services.OrganizationChart.Messages;
using MCMLXVII.BackEnd.Services.OrganizationChart.Interfaces;
using MCMLXVII.Tools.OrganizationChart.SmartEditors;
using MCMLXVII.Core.Common;
#endregion

namespace MCMLXVII.Tools.OrganizationChart.MembersClasses
{
    public class MemberSecurityGroup: MemberBase, iOrganizationTreeMemberAsGroup, iOrganizationTreeMemberAsDirectoryMember 
    {
        protected string _DirectoryIdentifier;
        protected string _LogonName;
        protected int _SecurityProviderID;
        protected string _SecurityProvider;
        protected msgMembershipInfo[] _Members;

        public override ucSmartBaseEditor GetEditor(bool UseGridEditor)
        {
            if (UseGridEditor)
                return new ucSmartGridEditor(this, base._NodeID);
            else
                return new ucSmartGroupEditor(this, base._NodeID);
        }


        public MemberSecurityGroup(): base()
        {         
        }

        public override void LoadMemberData(msgOrganizationMemberInfo memberInfo)
        {
            base.LoadMemberData(memberInfo);
            _DirectoryIdentifier = memberInfo.DirectoryIdentifier;
            _LogonName = memberInfo.LogonName;
            _SecurityProviderID = memberInfo.SecurityProviderID;
            _SecurityProvider = DirectoryConverter.GetSelectedItemDescription(_SecurityProviderID);
            _Members = memberInfo.MemberOf;
        }

        public override msgOrganizationMemberInfo GetMemberData()
        {
            return new msgOrganizationMemberInfo(base._MemberID, base._Description, base._NodeID, base._MemberClass, base._ClassProperties.OuterXml, _SecurityProviderID, _LogonName, _DirectoryIdentifier, "", new msgMembershipInfo(0, 0, ""), _Members, base._UpdateSequence);
        }


        [Browsable(false)]
        public override string MemberClassName
        {
            get { return "Group"; }
        }


        [Browsable(false)]
        public override System.Drawing.Icon GetIcon()
        {
            return Properties.Resources.icoGroup;

        }

        [ReadOnly(true), LocCategory("DirectoryService"), LocDescription("DirectoryID_Description"), LocDisplayName("DirectoryID_DisplayName")]
        public string DirectoryIdentifier
        {
            get
            {
                return _DirectoryIdentifier;
            }

            set
            {
                _DirectoryIdentifier = value;
                base.MarkChanges();
            }
        }
        [LocCategory("DirectoryService"), LocDescription("GroupName_Description"), LocDisplayName("GroupName_DisplayName"), Editor(typeof(DirectoryServiceGroupEditor), typeof(UITypeEditor))]
        public string LogonName
        {
            get
            {
                return _LogonName;
            }

            set
            {
                _LogonName = value;
                base.MarkChanges();
            }
        }
        [LocCategory("DirectoryService"), TypeConverter(typeof(DirectoryConverter)), LocDescription("DirService_Description"), LocDisplayName("DirService_DisplayName")]
        public string SecurityProvider
        {
            get
            {
                return _SecurityProvider;
            }

            set
            {
                _SecurityProvider = value;
                _SecurityProviderID = DirectoryConverter.GetSelectedItemID(_SecurityProvider);
                base.MarkChanges();
            }
        }
        [Browsable(false)]
        public int SecurityProviderID
        {
            get
            {
                return _SecurityProviderID;
            }

            set
            {
                _SecurityProviderID = value;
                base.MarkChanges();
            }
        }
        [LocCategory("Misc"), LocDescription("Members_Description"), LocDisplayName("Members_DisplayName"), Editor(typeof(UserGroupMembershipEditor), typeof(UITypeEditor)), TypeConverter(typeof(CollectionConverter))]
        public msgMembershipInfo[] Members
        {
            get
            {
                return _Members;
            }

            set
            {
                _Members = value;
                base.MarkChanges();
            }
        }
    }
}
